const { outPackModule } = require('../modules/outPackModule');
const { thingListModel } = require('../modules/thingListModule');
const { joinPackModule } = require('../modules/joinPackModule');
//添加出库
async function addOutPack(req, res, next) {
    const { arr, arr2 } = req.body;
    const result = await thingListModel.find({ _id: { $in: arr } });//查找物料
    const result1 = await thingListModel.updateMany({ _id: { $in: arr } }, { thingState1: true })//把物料在数据库操作出库
    if (result.length > 0 && result1.nModified > 0) {
        res.send({
            message: '获取成功',
            code: 200,
           
        })
    } else {
        res.send({
            message: '获取失败',
            code: 500,
        })
    }
}
//获取出库了的数据
async function getOutPack(req, res, next) {
    const result = await thingListModel.find({ thingState1: true });
    if(result.length>0){
        res.send({
            message:'获取成功',
            code:200,
            result
        })
    }else{
        res.send({
            message:'获取失败',
            code:500,
        })
    }
}
//删除出库
async function delOutPack(req, res, next) {
    const {_id}=req.body;
    const result = await thingListModel.updateOne({_id},{thingState1:false});
    if(result.nModified>0){
        res.send({
            message:'删除成功',
            code:200
        })
    }else{
        res.send({
            message:'删除失败',
            code:500
        })
    }
}
module.exports = {
    addOutPack, getOutPack,delOutPack
}